package com.example.customview;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

public class TestViewTwo extends LinearLayout {
    //data
    private Context context;
    //ui
    private TextView tvTitle;
    private TextView tvMessage;

    public TestViewTwo(Context context) {
        this(context,null);
    }

    public TestViewTwo(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public TestViewTwo(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        this.context = context;

        int padding = DisplayUtils.dpToPx(context,20);//20dp
        setOrientation(VERTICAL);
        setPadding(padding,padding,padding,padding);
        setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,DisplayUtils.dpToPx(context,150)));

        createChildView();

    }

    private void createChildView() {
        tvTitle = new TextView(this.context);
        tvTitle.setTextSize(30);
        tvTitle.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)
        );
        this.addView(tvTitle);

        tvMessage = new TextView(this.context);
        tvMessage.setTextSize(20);
        tvMessage.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)
        );
        this.addView(tvMessage);

    }

    public void setTitle(String title){
        tvTitle.setText(title);
    }

    public void setMessage(String message){
        tvMessage.setText(message);
    }
}
